{extend name="admin@publics/base"/}
{block name="title"}系统设置{/block}
{block name="body"}
<script>
/*==========控制器==========*/
Ext.define('admin.config.setting.CURDViewController', {
	extend: 'Tg.tx.CURDViewController',
	alias: 'controller._AdminConfigSettingController',
	_SettingSelect:function(_Btn){
		var _Me = this;
		var _VM = _Me.getView().getViewModel();
        _VM.set('_SettingGroup',_Btn.t)
    },
	_SettingInit:function(){
		var _Me = this;
		var _V = _Me.getView();
        var _Form = _V.down('form');
        Ext.Ajax.request({
            url: _PATH['site'] + '/admin/config/setting/t/1',
            method: 'GET',
            async: false,
            success: function(response, options) {
                var _Res = JSON.parse(response.responseText);
                if (_Res.code.toString() == '200') {
                    _Form.getForm().setValues(_Res.data);
                } else {
                    Ext.MessageBox.alert('失败', '数据异常');
                    _Win.close();
                }
            },
            failure: function(response, options) {
                Ext.MessageBox.alert('失败', '请求超时或网络故障');
            }
        });
    },
	_SettingSub:function(_Btn){
		var _Me = this;
		var _Form = _Btn.up('panel').down('form');
        var _Params= _Form.getValues();
        Ext.Ajax.request({
            url: _PATH['site'] + '/admin/config/setting',
            method: 'post',
			async: false,
            params: _Params,
            success: function (response, options) {
                var _Res = Ext.util.JSON.decode(response.responseText);
                if (parseInt(_Res.code) == 200) {
					Ext.toast({
						 title: '成功',
						 html: _Res.msg,
						 width: 200,
						 align: 'br'
					 });
                } else {
                    Ext.Msg.alert('错误 [代码：'+ _Res.code +']', _Res.msg);
                }
            },
            failure: function () {
				Ext.MessageBox.alert('失败', '请求超时或网络故障');
            }
        });
	},
});
/*==========模型==========*/
Ext.define('admin.config.setting.CURDViewModel', {
	extend: 'Tg.tx.CURDViewModel',
	alias: 'viewmodel._AdminConfigSettingViewModel',
    //Data
    data:{
        _SettingGroup:'1',
    },
});
/*==========视图==========*/
Ext.define('admin.config.setting', {
	extend: 'Ext.panel.Panel',
	alias: 'widget.admin_config_setting',
	requires: [
		'admin.config.setting.CURDViewController',
		'admin.config.setting.CURDViewModel',
	],
	controller: '_AdminConfigSettingController',
	viewModel: '_AdminConfigSettingViewModel',
    dockedItems: [
        {xtype: 'toolbar',dock: 'bottom',height: 50,style: 'background:#5fa2dd',items:[
                {text:'提交',handler: '_SettingSub'},
        ]},
        {xtype: 'toolbar',dock: 'top',items:[
            {xtype: 'label',text: '系统设置',style: 'font-size:16px; padding-right:10px;margin-right: 10px;border-right: dotted 1px #ccc;'},
            {volist name='ConfigGroup' id='vo'}
            {xtype: 'button',text: "{$vo['text']}",handler: '_SettingSelect',t:"{$vo['value']}"},
            {/volist}
        ]}
    ],
    items:{
    	xtype:'CURDForm',
        items:[
			{items: [
                {volist name='List' id='vo'}
                {name: '{$vo["name"]}',bind:{hidden:'{!(_SettingGroup == {$vo['group']})}'},fieldLabel: '{$vo["title"]}'},
                {/volist}
			]},
        ]
    },
    listeners: {
        afterrender:'_SettingInit',
    }
});
//实例化
Ext.application({
	name: 'admin',
	extend: 'Ext.app.Application',
	autoCreateViewport: 'admin.config.setting'
});
</script>
{/block}